﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：水价信息
//********************************************************************************//
using System;
using System.Web.UI;
using Entity;
using BLL;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.JiChuXX
{
    public partial class ShuiJiaXX : BasePage
    {
        #region 属性

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int ShuiJiaXXID
        {
            get
            {
                return Convert.ToInt32(ViewState["_ShuiJiaXXID"]);
            }
            set
            {
                ViewState["_ShuiJiaXXID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 水价信息对象
        /// </summary>
        YS_JX_SHUIJIAXX _YS_JX_SHUIJIAXX = new YS_JX_SHUIJIAXX();

        /// <summary>
        /// 水价信息BLL
        /// </summary>
        YS_JX_SHUIJIAXXBLL _YS_JX_SHUIJIAXXBLL = new YS_JX_SHUIJIAXXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        ///页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            //if (IsPostBack)
            //{
            //    LoadData(true);
            //}
            LoadData(true);
        }

        /// <summary>
        /// 重写Render方法，绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            if (e.Parameter == "search")
            {
                //要定位的记录局编号
                string conBH = this.txtConShuiJiaBH.Text.Trim();
                int findIndex = PageTools.SearchRecordIndex(this.dtSource, this.gvList, "S_SHUIJIABH", conBH, false);
                if (findIndex == -1)
                {
                    e.Result = e.Parameter + "|-1|未找到对应数据！";
                }
                else
                {
                    e.Result = e.Parameter + "|0|success|" + findIndex;
                }
            }
            else if (e.Parameter == "info")
            {
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                this._YS_JX_SHUIJIAXX = this._YS_JX_SHUIJIAXXBLL.SelectYS_JX_SHUIJIAXX(id);
                e.Result = string.Join("|", e.Parameter, "0", "success", this._YS_JX_SHUIJIAXX.S_SHUIJIABH, this._YS_JX_SHUIJIAXX.N_YSJ, this._YS_JX_SHUIJIAXX.D_KAISHI.Value.ToString("yyyy-MM-dd"), this._YS_JX_SHUIJIAXX.S_PIWENBH, this._YS_JX_SHUIJIAXX.S_SHUOMING);
            }
            else if (e.Parameter == "del")
            {
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                this._YS_JX_SHUIJIAXX = this._YS_JX_SHUIJIAXXBLL.SelectYS_JX_SHUIJIAXX(id);
                this._YS_JX_SHUIJIAXX.S_CAOZUOR = this.UserID.ToString();
                this._YS_JX_SHUIJIAXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                this._YS_JX_SHUIJIAXX.I_JLZT = -1;
                //执行水价信息操作
                _SYS_LOGBLL.Log<YS_JX_SHUIJIAXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "水价信息", OperateState.Delete, _YS_JX_SHUIJIAXX, null);
                if (_YS_JX_SHUIJIAXXBLL.InsertOrUpdate(_YS_JX_SHUIJIAXX, null))
                {
                    
                }
                e.Result = e.Parameter + "|0|操作成功！";
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                int id = Convert.ToInt32(this.hdCollection.Get("ID"));
                if(id<=0)
                {
                    operateState = OperateState.Add;
                    _YS_JX_SHUIJIAXX.ID = 0;
                    _YS_JX_SHUIJIAXX.I_JLZT = 0;
                }
                else
                {
                    //修改操作
                    operateState = OperateState.Modify;
                    _YS_JX_SHUIJIAXX = _YS_JX_SHUIJIAXXBLL.SelectYS_JX_SHUIJIAXX(id, null);
                }
                _YS_JX_SHUIJIAXX.S_SHUIJIABH = this.txtShuiJiaNo.Text;
                _YS_JX_SHUIJIAXX.N_YSJ = decimal.Parse(this.txtYongShuiJia.Text);
                _YS_JX_SHUIJIAXX.D_KAISHI = DateTime.Parse(this.txtKaiShiRQ.Text);
                _YS_JX_SHUIJIAXX.S_PIWENBH = this.txtShiPiWH.Text;
                _YS_JX_SHUIJIAXX.S_SHUOMING = this.txtShuoMing.Text;
                this._YS_JX_SHUIJIAXX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_SHUIJIAXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _SYS_LOGBLL.Log<YS_JX_SHUIJIAXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "水价信息", operateState, _YS_JX_SHUIJIAXX, null);
                if (_YS_JX_SHUIJIAXXBLL.InsertOrUpdate(_YS_JX_SHUIJIAXX, null))
                {
                    
                    e.Result = e.Parameter + "|0|保存成功！";
                }
            }
        }

        /// <summary>
        /// 加载列表
        /// </summary>
        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            this.LoadData(true);
        }

        #endregion

        #region 方法

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData(bool reget)
        {
            if (reget)
            {
                this.dtSource = _YS_JX_SHUIJIAXXBLL.SelectYS_JX_SHUIJIAXXesDynamic("I_JLZT=0 ", "D_KAISHI DESC");
            }
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }       

        #endregion        
    }
}